package com.xzkydz.all_sensor.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.serialport.bean.ShowInf;
import com.xzkydz.all_sensor.allsensor.R;

import java.util.List;

/**
 * Created by 于坤 on 2016/9/5.
 * 单位名称适配器
 */
public class UnitAdapter extends BaseAdapter {

    private List<ShowInf> list ;
    private Context mContext;
    public UnitAdapter(Context mContext, List<ShowInf> list) {
        this.mContext = mContext;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        Log.d("122","刷新单位");
        ViewHolder3 viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder3();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_showinf, null);
            viewHolder.textView1 = (TextView)view.findViewById(R.id.textView1);
            viewHolder.textView2 = (TextView)view.findViewById(R.id.textView2);
            viewHolder.textView3 = (TextView)view.findViewById(R.id.textView3);
            viewHolder.textView4 = (TextView)view.findViewById(R.id.textView4);
            viewHolder.textView5 = (TextView)view.findViewById(R.id.textView5);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder3) view.getTag();
        }
        if (i==0){
            viewHolder.textView1.setText("编号");
            viewHolder.textView2.setText(list.get(i).getString());
            viewHolder.textView3.setText(list.get(i).getString1());
            viewHolder.textView4.setText(list.get(i).getString2());
            viewHolder.textView5.setText(list.get(i).getString3());
        }else {
            viewHolder.textView1.setText(i+"");
            viewHolder.textView2.setText(list.get(i).getString());
            viewHolder.textView3.setText(list.get(i).getString1());
            viewHolder.textView4.setText(list.get(i).getString2());
            viewHolder.textView5.setText(list.get(i).getString3());
        }

        return view;
    }
}

final  class ViewHolder3 {
    TextView textView1;
    TextView textView2;
    TextView textView3;
    TextView textView4;
    TextView textView5;
}
